package com.aws.controller;

import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.model.*;
import com.aws.service.AwsService;
import lombok.extern.slf4j.Slf4j;
import org.apache.http.impl.bootstrap.HttpServer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.RandomAccessFile;
import java.net.http.HttpResponse;
import java.util.ArrayList;
import java.util.List;

/**
 * @description:
 * @author: libugu@cskaoyan.com
 * @date 2024/1/26 - 17:12
 */
@Slf4j
@RestController
public class TestController {

    @Autowired
    AwsService awsService;


    @PostMapping(value = "/aws/singleUpload")
    public String singleUpload(@RequestParam("uploadFile") MultipartFile uploadFile) {

        awsService.singleUpload(uploadFile);

        return "File upload success";
    }

    @PostMapping(value = "/aws/segmentUpload")
    public String segmentUpload(@RequestParam("uploadFile") MultipartFile uploadFile) {
        awsService.segmentUpload(uploadFile);
        return "File upload success";
    }


    @GetMapping(value = "/aws/singleDownload")
    public String singleDownload(@RequestParam("downloadPath") String downloadPath, HttpServletResponse response)  {
        awsService.singleDownload(downloadPath,response);
        return "File download success";
    }
    @GetMapping(value = "/aws/getAllFiles")
    public String getAllFiles()  {
        awsService.getAllFiles();
        return "GetAllFiles success";
    }

    @GetMapping(value = "/aws/deleteSingleFile")
    public String deleteSingleFile(@RequestParam("deletePath") String deletePath)  {
        awsService.deleteSingleFile(deletePath);
        return "DeleteSingleFile success";
    }



}
